package com.gui;

import com.gooddies.wiring.annotations.Wire;
import com.gooddies.wiring.annotations.WiringComponent;
import com.gui.textFields.TextUtils;
import javax.swing.JTextPane;

/**
 * @author Dmitry
 */
@WiringComponent(singleton = true)
public class LineNumberCalculator {
    @Wire(value = "GrammarEditor")
    private JTextPane textPane;

    public int computeLineNumber(int offset) {
        return getTextLineNumber(offset);
    }

    protected int getTextLineNumber(int rowStartOffset) {
        return TextUtils.getLineOfOffset(textPane, rowStartOffset);
        /*Element root = textPane.getDocument().getDefaultRootElement();
         int index = root.getElementIndex(rowStartOffset);
         Element line = root.getElement(index);
         if (line.getStartOffset() == rowStartOffset) {
         return index;
         } else {
         return -1;
         }*/
    }
}
